# -*- encoding:utf-8 -*-
# @Time : 2025/3/18 19:56
# @Author : xunter
# @Email : 3133739348@qq.com
# @File : tasks.py
# @Software : PyCharm
import logging

from django.core.mail import send_mail

from celery_tasks.celery_main import app

logger = logging.getLogger()
@app.task(name='send_mail_task')
def send_mail_task(email,html_message):
    """
    邮箱发送任务处理函数 异步任务
    :param email: 收件人邮箱账号
    :param html_message: 邮箱内容 可以发送HTML程序
    :return:
    """
    try:
        res_email = send_mail(
            subject='维购国际商城',
            message='',
            html_message=html_message,
            from_email=None,
            recipient_list=[email]
        )
    except Exception as e:
        logger.error(f'邮箱发送异常[email:{email},message{e}]')
    else:
        if res_email:
            logger.info(f'邮箱发送成功[email:{email}]')
        else:
            logger.warning(f'邮箱发送失败[email:{email}]')
